<script setup>
import { ref, defineProps } from "vue";

const props = defineProps({
  modelValue: {
    type: Boolean,
    default: false,
  },
});
const emit = defineEmits(["cancel"]);

const ishowcamera = ref(false);
const textName = ref("");

const getPom = (t, f) => {
  textName.value = t;
  const systemInfo = uni.getSystemInfoSync();
  if (systemInfo.osName === "android") {
    if (uni.getStorageSync("isspermission")) {
    } else {
      ishowcamera.value = true;
    }

    plus.android.requestPermissions(["android.permission.CAMERA"], (e) => {
      if (e.deniedAlways.length > 0) {
        // 弹出提示框解释为何需要权限，引导用户打开设置页面开启

        ishowcamera.value = false;
        emit("cancel");
      } else if (e.deniedPresent.length > 0) {
        //权限被临时拒绝
        // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限
        ishowcamera.value = false;
        emit("cancel");
      } else if (e.deniedAlways.length > 0) {
        //权限被永久拒绝
        // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限
        ishowcamera.value = false;
        emit("cancel");
      } else {
        plus.android.requestPermissions(
          ["android.permission.READ_EXTERNAL_STORAGE"],
          (e) => {
            if (e.deniedAlways.length > 0) {
              // 弹出提示框解释为何需要权限，引导用户打开设置页面开启

              ishowcamera.value = false;
              emit("cancel");
            } else if (e.deniedPresent.length > 0) {
              //权限被临时拒绝
              // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限

              ishowcamera.value = false;
              emit("cancel");
            } else if (e.deniedAlways.length > 0) {
              //权限被永久拒绝
              // 弹出提示框解释为何需要权限，可再次调用plus.android.requestPermissions申请权限

              ishowcamera.value = false;
              emit("cancel");
            } else {
              ishowcamera.value = false;
              uni.setStorageSync("isspermission", true);

              f();
            }
          }
        );
      }
    });
    return;
  } else {
    f();
  }
};

defineExpose({
  getPom,
});
</script>

<template>
  <view class="show-camera" v-if="ishowcamera">
    <view class="show-camera-k">
      <view class="show-sm"> 设备权限使用说明 </view>
      <view class="show-des">
        {{ textName }}
      </view>
    </view>
  </view>
</template>

<style lang="scss" scoped>
.show-camera {
  width: 100%;
  position: fixed;
  z-index: 9999999;
  top: 0rpx;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.3);
  margin: 0 auto;
  margin-top: 120rpx;

  .show-camera-k {
    width: 80%;
    margin: 0 auto;
    margin-top: 60rpx;
    padding: 30rpx;
    color: #000000;
    background-color: rgba(255, 255, 255, 1);
    border-radius: 20rpx;

    .show-sm {
      font-weight: bold;
      font-size: 26rpx;
    }

    .show-des {
      margin-top: 10rpx;
      font-size: 22rpx;
    }
  }
}
</style>

<!--
使用方法
  <view @click="goInQx">获取权限</view>
 <pomiss ref="pomissview" v-model="isshowcamera"></pomiss>
import pomiss from "@/components/pomiss/index.vue";
const pomissview = ref(null);

const goInQx = () => {
  // #ifdef APP-PLUS
  isshowcamera.value = true;
  pomissview.value.getPom("这个是我的权限要求,请先允许", () => {
    console.log("允许");
    isshowcamera.value = false;
  });
  // #endif
}; -->
